<!DOCTYPE html>
<html>
<head>
    <title>我的游记</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/userTravels.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.js"></script>
    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem('user'));
            //当前页input框
            var currentPage = $("#currentPage");
            //游记总页数
            var pages =1;
            //用于存储游记列表的数据
            var travelDate = [];

            //分页查询的方法
            function query() {
                //当前页的值
                var currentPageValue = currentPage.val();
                //每页显示数量
                var pageSize = $("#pageSize").val();

                //获取游记列表
                $.get('/users/' + user.id + "/travels", {
                    currentPage: currentPageValue,
                    pageSize: pageSize
                }, function (data) {
                    //往数组容器中存数据(把第二个数组的内容合并到第一个数组中)
                    $.merge(travelDate, data.list);

                    //渲染数据
                    $(".travels").renderValues({list: travelDate});
                    //当前页加一(确保获取到第二页数据后currentPage再加一)
                    currentPage.val(parseInt(currentPageValue) + 1);
                    //设置总页数的值
                    pages = data.pages;
                    //给a链接绑定时间 (渲染完后才可以绑定)
                    $("a[data-url]").click(function () {
                        var url = $(this).data("url");
                        var id=$(this).data("id");
                        window.location.href=url+id;
                    })
                })


            }

            //默认查询第一页数据
            query();

            //滚动事件
            $(window).scroll(function () {
                //document(html)卷上去的高度+窗口的高度>+document(html)的整个高度
                if ($(document).scrollTop() + $(window).height() >= $(document).height()) {
                    //当前页的值
                    var currentPageValue = currentPage.val();
                    //判断currentPageValue当前页是否大于pages总页数
                    if (currentPageValue <= pages) {
                        query();

                    } else {
                        //提示用户已经到底了

                        $(document).dialog({
                            type: 'notice',
                            infoText: '已经到底了',
                            autoClose: 1000
                        });

                    }
                }
            })




        })


    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="profiles.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的游记</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<input type="hidden" name="currentPage" id="currentPage" value="1">
<input type="hidden" name="pageSize" id="pageSize" value="3">

<div class="container travels">
    <dl class="list" render-loop="list">
        <dd>
            <a href="javascript:;" data-url="/mine/editTravels.html?id=" render-attr="data-id=list.id">
                <img render-src="list.coverUrl">
                <h6 class="title" render-html="list.title"></h6>
                <p>最近更新时间 <span render-html="list.lastUpdateTime"></span>
                    <span class="span-right">
							  <i class="fa fa-heart"></i><span>0</span>收藏
						  <i class="fa fa-thumbs-o-up"></i><span>0</span>点赞</span>
                </p>
            </a>
        </dd>
    </dl>
</div>

</body>
</html>
